# -*- coding: utf-8 -*-

from datetime import date

from django.contrib.auth import logout
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect

from ..models import Clientes

def main_page(request):
    """Pagina de inicio"""
    # Cumples del mes
    cliente_mes = Clientes.objects.filter(cumple__month=date.today().month)
    clientes_por_dia = [(cli.cumple.day, cli) for cli in cliente_mes]
    clientes_por_dia.sort()
    cliente_mes = [cPorDia[1] for cPorDia in clientes_por_dia]
    variables = RequestContext(request, {
        'cumples_mes': cliente_mes,
    })
    return render_to_response('main.html', variables)


def logout_page(request):
    """Cierra sesion"""
    logout(request)
    return HttpResponseRedirect('/')